<template>
  <view class="order-center">
    <!-- 顶部订单状态 -->
    <scroll-view scroll-x="true" class="order-status-bar">
      <view style="display: flex; flex-direction: row;">
        <view
          v-for="(item, index) in orderStatus"
          :key="index"
          :class="['order-status-item', activeIndex === index ? 'active' : '']"
          @tap="selectStatus(index)"
        >
          {{ item.text }}
        </view>
      </view>
    </scroll-view>

    <!-- 下方订单列表 -->
    <view class="order-list">
      <view class="order-item" v-for="(order, index) in orders" :key="index" v-on:click="onItemClick()">
        <view class="order-content">
          <view class="order-info">
            <view class="order-title">{{ order.title }}</view>
            <view class="order-location">{{ order.location }}</view>
            <view class="order-price">{{ order.price }}</view>
          </view>
          <view class="order-status">
            <view>{{ order.status }}</view>
            <view>{{ order.date }}</view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      orderStatus: [
        { text: '全部订单' },
        { text: '新订单' },
        { text: '已支付' },
        { text: '已核销' },
        { text: '已退款' }
      ],
      activeIndex: 0, // 当前激活的状态索引
      orders: [
        {
          title: "七夕之夜-云杉动漫视听交响音乐",
          location: "票巴扎 新疆人民剧场",
          price: "120.00/共1张",
          status: "已取消",
          date: "2024-08-10 21:00",
        },
        {
          title: "七夕之夜-云杉动漫视听交响音乐",
          location: "票巴扎 新疆人民剧场",
          price: "740.00/共5张",
          status: "已取消",
          date: "2024-08-10 21:00",
        },
        {
          title: "【伊宁】《懒边子即兴喜剧》",
          location: "票巴扎 伊宁市环球港7楼影城",
          price: "178.00/共2张",
          status: "已取消",
          date: "2024-08-11 21:30",
        },
		{
		  title: "【伊宁】《懒边子即兴喜剧》1",
		  location: "票巴扎 伊宁市环球港7楼影城",
		  price: "178.00/共2张",
		  status: "已取消",
		  date: "2024-08-11 21:30",
		},
      ],
    };
  },
  methods: {
    selectStatus(index) {
      this.activeIndex = index;
      // 根据activeIndex获取对应状态的订单数据
      this.fetchOrderData(index);
    },
    fetchOrderData(index) {
      // 在这里根据 index 值来获取不同状态的订单数据
      // 例如：调用API获取订单数据并更新页面
      console.log("Fetching data for status index:", index);
    },
    onItemClick() {
      uni.navigateTo({
        url: '/pages/order_list/order_detail/order_detail'
      }); 
    }
  }
};
</script>

<style>
.order-center {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

.order-status-bar {
  position: fixed; /* 将 scroll-view 固定在顶部 */
  top: 0;
  left: 0;
  right: 0;
  background-color: #f5f5f5;
  padding: 10px 0;
  z-index: 10;
  overflow-x: auto; /* 使得内容可以横向滚动 */
}

.order-status-item {
  flex-shrink: 0; /* 防止子项缩小 */
  padding: 10px 20px;
  font-size: 16px;
  color: #333;
  cursor: pointer;
}

.order-status-item.active {
  color: #007aff;
  border-bottom: 2px solid #007aff;
}

.order-list {
  flex: 1;
  padding: 20px 10px 10px 10px;
  margin-top: 60px; /* 确保订单列表不会被固定的顶部 scroll-view 遮挡 */
  background-color: #f5f5f5;
}

.order-item {
  background-color: #fff;
  border-radius: 8px;
  margin-bottom: 10px;
  padding: 15px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.order-content {
  display: flex;
  justify-content: space-between;
}

.order-info {
  display: flex;
  flex-direction: column;
}

.order-title {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 5px;
}

.order-location {
  font-size: 14px;
  color: #888;
  margin-bottom: 10px;
}

.order-price {
  font-size: 16px;
  color: #333;
}

.order-status {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: space-between;
  font-size: 14px;
  color: #888;
}

.order-status view:first-child {
  color: #ff4d4f;
}
</style>
